const app = new Vue({
    el:'#app',
    data:{
        books:[
            {
            id:1,
            name:'<<算法导论>>',
            date:'2006-9',
            price:85.00,
            count:1
        },
        {
            id:2,
            name:'<<数据结构>>',
            date:'2007-9',
            price:60.00,
            count:3
        }
        ,
        {
            id:3,
            name:'<<金瓶梅>>',
            date:'2012-9',
            price:32.00,
            count:12
        }
        ],
        inputtest:'有芝麻',
        sex:'男',
        sports:''
    },
    methods:{
        getFinalPrice(price){
          
            return '￥'+ price.toFixed(2)
        },
        decrement(index){
            
           this.books[index].count--
        },
        increment(index){
            this.books[index].count++
        },
        removeHandle(index){
            this.books.splice(index,1)
        }
    },
    computed:{
        totalPrice(){
            let totalPrice = 0;    
            // for(let i=0;i<this.books.length;i++){
            //     totalPrice += this.books[i].count*this.books[i].price
            // }
            for(let book of this.books){
                totalPrice += book.count*book.price
            }
            return totalPrice
        }
    },
    filters:{
        showPrice(price){
            return '￥'+ price.toFixed(2)
        }
    }
})